<template>
    <div class="">
        <el-dialog title="编辑社保" :visible.sync="dialog" width="40%" :before-close="dialogClose">
            <el-form ref="formData" :model="formData" label-width="100px">
				<el-form-item label="个人信息" prop="userid">
				    <el-select filterable v-model="formData.userid" style="width: 100%;" placeholder="请选择个人信息">
				    	<el-option :label="item.name" :value="item.id" v-for="(item, index) in User"></el-option>
				    </el-select>
				</el-form-item>
<!-- 				<el-form-item label="姓名" prop="name">
				    <el-input v-model="formData.name" placeholder="请输入姓名"></el-input>
				</el-form-item> -->
				<el-form-item label="类别" prop="sex">
					<el-select v-model="formData.type" style="width: 100%;" placeholder="请选择类别">
						<el-option label="养老保险" :value="1"></el-option>
						<el-option label="医疗保险" :value="2"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="年份(年)" prop="amount">
					<el-date-picker
					  v-model="formData.date"
					  type="year"
					  value-format="yyyy"
					  placeholder="请输入年份">
					</el-date-picker>
				</el-form-item>
<!-- 				<el-row>
					<el-col :span="12">
						<el-form-item label="手机号" prop="phone">
						    <el-input v-model="formData.phone" placeholder="请输入手机号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="身份证号" prop="idcard">
						    <el-input v-model="formData.idcard" placeholder="请输入身份证号"></el-input>
						</el-form-item>
					</el-col>
				</el-row> -->
				<el-form-item label="应缴金额" prop="amount">
				    <el-input v-model="formData.money" placeholder="请输入应缴金额"></el-input>
				</el-form-item>
<!-- 				<el-row>
					<el-col :span="12">
						<el-form-item label="应缴金额" prop="amount">
						    <el-input v-model="formData.money" placeholder="请输入应缴金额"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="实缴金额" prop="money">
						    <el-input v-model="formData.money" placeholder="请输入实缴金额"></el-input>
						</el-form-item>
					</el-col>
				</el-row> -->
				
            	<el-form-item>
            		<el-button @click="dialogClose">取 消</el-button>
            		<el-button type="primary" @click="formSubmit">确 定</el-button>
            	</el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
	import { regionData, codeToText} from 'element-china-area-data'
    export default {
        data() {
			return {
				dialog: false,
				options: regionData,
				User: [],
				Site: [],
				formData: {
					id: 0,
					userid: '', //个人id
					amount: '', //应缴金额
					money: '', //实缴金额
				}
			}
        },
		created() {
		},
		watch: {
			dialog () {
				if(!this.dialog) {
					this.clearFormData()
					this.$emit('getData')
				} else {
					this.getUser()
				}
			}
		},
        methods: {
			getUser () {
				this.$apiPost('User/getUser').then(res => {
					if(res.code == 1) {
						this.User = res.data
					}
				})
			},
			dialogClose(){
				this.$emit('dialogToggle')
			},
			clearFormData () {
				for(let i in this.formData){
					if(i == 'id') {
						this.formData[i] = 0
					} else {
						this.formData[i] = ''
					}
				}
			},
			// 保存编辑
			formSubmit() {
				this.$apiPost('Pension/editData', this.formData).then(res => {
					if(res.code == 1) {
						this.$message(res.msg)
						this.dialogClose()
					} else {
						this.$message(res.msg)
					}
				})
			},
        }
    };
</script>
<style scoped>
	.mselect{
		width: 100%;
	}
	.mtdiv{
		margin-top: 10px;
		display: inline-block;
		width: 100%;
	}
	.mtdiv .mtdiv-v{
		float: left;
		width: 50%;
		margin-bottom: 5px;
		display: flex;
		align-items: center;
	}
	.mtdiv .mtdiv-v label{
		float: left;
		margin-right: 10px;
	}
	.mtdiv .el-input{
		float: left;
		width: 80%;
		margin: 5px 0;
	}
	.el-cascader {
		line-height: 32px !important;
	}
	.el-input__inner {
	    height: 32px !important;
	    line-height: 32px !important;
	}
	.el-input__icon {
		line-height: 32px !important;
	}
</style>
